package com.hsylient.javase.chapter12.demo01.tcp;

import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 服务端
 */
public class Server {
    public static void main(String[] args) throws Exception {
        // 创建服务
        ServerSocket serverSocket = new ServerSocket(9000);
        // 监听客户端连接
        Socket accept = serverSocket.accept();
        // 获取输入流
        InputStream inputStream = accept.getInputStream();
        byte[] bytes = new byte[1024];
        int readLen;
        while ((readLen = inputStream.read(bytes)) != -1) {
            System.out.println(new String(bytes, 0, readLen).trim());
        }
        inputStream.close();
//        serverSocket.close();
    }
}
